package io.renren.modules.jsf.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.jsf.entity.TContentEntity;
import io.renren.modules.jsf.service.TContentService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author chen
 * @email sun@gmail.com
 * @date 2023-03-30 01:33:21
 */
@RestController
@RequestMapping("jsf/tcontent")
public class TContentController {
    @Autowired
    private TContentService tContentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = tContentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TContentEntity tContent = tContentService.getById(id);

        return R.ok().put("tContent", tContent);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TContentEntity tContent) {
        tContent.setCrateAt(new Date());
        tContentService.save(tContent);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("jsf:tcontent:update")
    public R update(@RequestBody TContentEntity tContent) {
        tContentService.updateById(tContent);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("jsf:tcontent:delete")
    public R delete(@RequestBody Integer[] ids) {
        tContentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
